package com.own.business.resource.entity.vo;

import com.own.business.resource.entity.po.FileRecord;
import com.own.component.common.base.entity.vo.BaseCreateVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * FileRecordVo
 *
 * @author chenxueli
 * @date 2021/09/15 14:16:44
 */
@Schema(title = "文件记录表" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class FileRecordVo extends BaseCreateVo<FileRecord> implements Serializable {

    @Schema(title = "文件名称")
    private String name;

    @Schema(title = "文件原名称")
    private String oldName;

    @Schema(title = "文件地址（相对路径）")
    private String path;

    @Schema(title = "文件位置")
    private String position;

    @Schema(title = "文件类型")
    private String type;

    @Schema(title = "文件大小（字节）")
    private Long size;

    @Schema(title = "文件的md5值")
    private String md5;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public FileRecordVo(@NonNull FileRecord entity) {
        super(entity);
        this.name = entity.getName();
        this.oldName = entity.getOldName();
        this.path = entity.getPath();
        this.position = entity.getPosition();
        this.type = entity.getType();
        this.size = entity.getSize();
        this.md5 = entity.getMd5();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public FileRecord toPo(FileRecord entity) {
        if (entity == null) {
            entity = new FileRecord();
        }
        entity.setName(this.name);
        entity.setOldName(this.oldName);
        entity.setPath(this.path);
        entity.setPosition(this.position);
        entity.setType(this.type);
        entity.setSize(this.size);
        entity.setMd5(this.md5);
        return super.toPo(entity);
    }

}
